package com.sinopec.basemodule.widget

import android.annotation.TargetApi
import android.content.Context
import android.os.Build
import android.util.AttributeSet
import android.view.View
import android.view.WindowInsets
import android.widget.FrameLayout

/**
 * 创建人：lwj<br/>
 * 创建时间：2019/9/12 13:26 <br/>
 */
class FitSystemWindowFrameLayout @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : FrameLayout(context, attrs, defStyleAttr) {
    init {
        setOnHierarchyChangeListener(object : OnHierarchyChangeListener {
            override fun onChildViewRemoved(parent: View?, child: View?) {

            }

            @TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
            override fun onChildViewAdded(parent: View?, child: View?) {
                requestApplyInsets()
            }

        })
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    override fun dispatchApplyWindowInsets(insets: WindowInsets): WindowInsets {
//        super.dispatchApplyWindowInsets(insets)
        for (i in 0 until childCount) {
            val view = getChildAt(i)
            view.dispatchApplyWindowInsets(insets)
        }
        return insets
    }
}